package com.yangziqiang.config;

import com.yangziqiang.common.MsgResult;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName GlobalExceptionHandler
 * @Description TODO 全局异常拦截
 * @Author 18516
 * @DATE 2022/1/19 16:02:30
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    //    异常
    @ExceptionHandler
    public MsgResult handlerException(Exception e) {
        e.printStackTrace();
        return MsgResult.fail(500, e.getMessage(), null);
    }

    //    捕获自定义异常抛出
    @ExceptionHandler(BizException.class)
    public MsgResult handlerException(BizException biz) {
        biz.printStackTrace();
        return MsgResult.fail(biz.getErrCode(), biz.getMessage(), null);
    }

}
